package com.cppba.controller;


import com.cppba.dto.UserDto;
import com.cppba.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {
    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping("/getById")
    @ResponseBody
    public UserDto getById(Long id) {
        return userService.getById(id);
    }

    @RequestMapping("/page")
    @ResponseBody
    public PageInfo page(
            String username,
            @RequestParam(name ="pageNumber",defaultValue = "1") Integer pageNumber,
            @RequestParam(name ="pageSize",defaultValue = "2")Integer pageSize) {
        PageInfo<UserDto> pageInfo = userService.page(username, pageNumber, pageSize);
        return pageInfo;
    }
}
